package cn.cdeden.knowledge.service.impl;

import cn.cdeden.common.core.config.FileProperties;
import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.common.mybatis.validator.QueryHelpMybatisPlus;
import cn.cdeden.common.oss.enumd.OssBucketOneEnum;
import cn.cdeden.common.oss.enumd.OssModuleType;
import cn.cdeden.common.satoken.utils.LoginHelper;
import cn.cdeden.knowledge.domain.*;
import cn.cdeden.knowledge.domain.dto.*;
import cn.cdeden.knowledge.domain.vo.PersonalFilesTreeVo;
import cn.cdeden.knowledge.enums.*;
import cn.cdeden.knowledge.mapper.FilesCollectionMapper;
import cn.cdeden.knowledge.mapper.TeamFilesTreeMapper;
import cn.cdeden.knowledge.mapper.TeamMapper;
import cn.cdeden.knowledge.service.*;
import cn.cdeden.knowledge.utils.FileUtil;
import cn.cdeden.knowledge.utils.PageUtil;
import cn.cdeden.knowledge.utils.SetAttentionDataUtil;
import cn.cdeden.knowledge.utils.SetCollectionDataUtil;
import cn.cdeden.resource.api.RemoteFileService;
import cn.cdeden.resource.api.RemoteOssEsService;
import cn.cdeden.resource.api.domain.*;
import cn.cdeden.system.api.RemoteUserService;
import cn.cdeden.system.api.domain.enums.FileTypeEnum;
import cn.cdeden.system.api.model.LoginUser;
import cn.hutool.core.util.ObjectUtil;
import cn.cdeden.knowledge.mapper.FilesAttentionMapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Joiner;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Chen
 * @date 2022-09-16
 */
@Service
@AllArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TeamFilesTreeServiceImpl extends ServiceImpl<TeamFilesTreeMapper, TeamFilesTree> implements TeamFilesTreeService {

    private final TeamFilesTreeMapper teamFilesTreeMapper;
    private final TeamMapper teamMapper;
//    private final FileStorageUtils fileStorageUtils;
    private final RemoteFileService remoteFileService;

    private final FilesCollectionMapper filesCollectionMapper;

    private final FilesAttentionMapper filesAttentionMapper;

    private final TeamRoleService teamRoleService;

    private final TeamRelevanceRoleService teamRelevanceRoleService;


    private final EnterpriseFilesTreeService enterpriseFilesTreeService;

    private final EnterpriseFolderTreeService enterpriseFolderTreeService;

    private final TeamToEnterpriseService teamToEnterpriseService;
    @DubboReference
    private final RemoteOssEsService remoteOssEsService;
    @DubboReference
    private final RemoteUserService remoteUserService;

    private final SysDocLogService sysDocLogService;

    private final TeamTemplateTreeService teamTemplateTreeService;

    @Override
    public TableDataInfo<TeamFilesTreeDto> queryAll(TeamFilesTreeQueryParam query, Pageable pageable) {
        List<TeamRelevanceRole> relevanceRole = teamRelevanceRoleService.getRelevanceRole(query.getTeamId(), LoginHelper.getUserId(), null);
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectListTreePage(null, query.getRealName(), query.getTeamId(), relevanceRole, pageable.getPageNumber() * pageable.getPageSize(), pageable.getPageSize(), true, query.getAsc(), query.getDesc(), query.getSort(), null);
        int count = teamFilesTreeMapper.selectListTreePageCount(null, query.getRealName(), true, query.getTeamId(), relevanceRole);
        List<TeamFilesTreeDto> teamFilesTreeDtos = MapstructUtils.convert(teamFilesTrees, TeamFilesTreeDto.class);
        for (TeamFilesTreeDto teamFilesTreeDto : teamFilesTreeDtos) {
            teamFilesTreeDto.setCreateBy(teamFilesTreeDto.getCreateId());
            teamFilesTreeDto.setUpdateBy(teamFilesTreeDto.getUpdateId());
        }
        TableDataInfo<TeamFilesTreeDto> teamFilesTreeDtoPageInfo = new TableDataInfo<>();
        teamFilesTreeDtoPageInfo.setRows(teamFilesTreeDtos);
        teamFilesTreeDtoPageInfo.setPageSize(pageable.getPageSize());
        teamFilesTreeDtoPageInfo.setPage(pageable.getPageNumber());
        teamFilesTreeDtoPageInfo.setTotal(count);

        return teamFilesTreeDtoPageInfo;
    }

    @Override
    public TeamFilesTreeDto queryAll(TeamFilesTreeQueryParam query) {
        String id = query.getId();

        List<String> treeNodeIds = null;
        if (query.getId() != null) {
            treeNodeIds = teamFilesTreeMapper.getByPatentId(query.getId());
        }

        QueryWrapper<TeamFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);
        predicate.eq("id", id);
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectList(predicate);
        if (teamFilesTrees.size() == 1) {
            TeamFilesTreeDto teamFilesTreeDto = MapstructUtils.convert(teamFilesTrees.get(0), TeamFilesTreeDto.class);
            query.setId(null);
            return getData(teamFilesTreeDto, teamFilesTrees.get(0).getTeamId(), id, treeNodeIds, query);
        }
        return null;
    }

    @Override
    public TeamFilesTreeDto createFolder(TeamFilesTreeInsertParam teamFilesTreeInsertParam, String userId) {
        String teamId = teamFilesTreeInsertParam.getTeamId();
        String parentId = teamFilesTreeInsertParam.getParentId();

        TeamFilesTreeDto teamFilesTreeDto = insert(parentId, teamFilesTreeInsertParam.getRealName(), teamId, TreeTypeEnum.FOLDER.getType(), userId);

        if (!teamFilesTreeDto.getDuplicate()) {
            //继承上级权限
            List<TeamRelevanceRoleDto> list = teamRelevanceRoleService.extendParentPerm(parentId, String.valueOf(teamFilesTreeDto.getId()));

            //创建日志
            for (TeamRelevanceRoleDto relevanceRoleDto : list) {
                relevanceRoleDto.setPermJson(teamRoleService.getById(relevanceRoleDto.getRoleId()).getParams());
            }
            List<SysLogPerm> collect = list.stream().map(res -> new SysLogPerm(res.getObjectId(), res.getObjectType(), res.getPermJson(), res.getRoleId())).collect(Collectors.toList());
            sysDocLogService.createPermLog(String.valueOf(teamFilesTreeDto.getId()), null, TreeEnum.TEAM, OperationEnum.INSERT.getOperation(OperationEnum.OperationTypeEnum.FOLDER), teamFilesTreeDto.getRealName(), teamFilesTreeDto.getPath(), null, collect);
        }
        return teamFilesTreeDto;
    }

    @Override
    public TeamToEnterpriseDto assembleTeamToEnterprise(String id){
        TeamFilesTree teamFilesTree = getById(id);

        //判断是否有权限
        if (!teamRelevanceRoleService.checkPermission(id, teamFilesTree.getTeamId(), LoginHelper.getLoginUser(), TeamParamEnum.COMMIT_ENTERPRISE.getParam())) {
            return null;
        }

        TeamToEnterpriseDto teamToEnterprise = MapstructUtils.convert(teamFilesTree, TeamToEnterpriseDto.class);
        List<TeamFilesTree> list = this.lambdaQuery().eq(TeamFilesTree::getParentId, teamFilesTree.getId()).list();
        //添加子级
        for (TeamFilesTree filesTree : list) {
            TeamToEnterpriseDto ChildTeamToEnterprise = assembleTeamToEnterprise(String.valueOf(filesTree.getId()));
            if (ChildTeamToEnterprise != null){
                teamToEnterprise.getChildren().add(ChildTeamToEnterprise);
            }
        }
        return teamToEnterprise;
    }

    @Override
    public Long insertByPath(String path, String parentId, String teamId, String userId) {
        //拆分路径
        String[] split = path.split("/");
        if (parentId == null) {
            Team team = teamMapper.selectById(teamId);
            parentId = team.getHeadNodeId();
        }

        if (userId == null) {
            userId = String.valueOf(LoginHelper.getUserId());
        }

        //团队角色权限
        if (!teamRelevanceRoleService.checkPermission(parentId, teamId, remoteUserService.getUserInfo(Long.valueOf(userId)), TeamParamEnum.ADD.getParam())) {
            throw new RuntimeException("无新建权限，请联系管理员");
        }

        Long createParentId = null;
        for (String s : split) {
            TeamFilesTree teamFilesTree = nameRechecking(s, parentId, null);
            if (teamFilesTree == null) {
                //逐级创建
                TeamFilesTreeDto teamFilesTreeDto = createFolder(new TeamFilesTreeInsertParam(s, parentId, teamId), userId);
                parentId = String.valueOf(teamFilesTreeDto.getId());
                createParentId = teamFilesTreeDto.getId();
            } else {
                parentId = String.valueOf(teamFilesTree.getId());
                createParentId = teamFilesTree.getId();
            }
        }
        return createParentId;
    }

    @Override
    public List<TeamFilesTreeDto> selectAll(String parentId) {
        QueryWrapper<TeamFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(new TeamFilesTreeQueryParam());
        predicate.eq("parent_id", parentId);
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectList(predicate);
        return MapstructUtils.convert(teamFilesTrees, TeamFilesTreeDto.class);
    }

    /**
     * 查询数据并以要求格式返回
     *
     * @param teamFilesTreeDto 团队文档树对象
     * @param teamId           团队ID
     * @return 分页或对象
     */
    private TeamFilesTreeDto getData(TeamFilesTreeDto teamFilesTreeDto, String teamId, String parentId, List<String> treeNodeIds, TeamFilesTreeQueryParam query) {

        LoginUser user = LoginHelper.getLoginUser();
        Long id = user.getUserId();

        List<TeamRelevanceRole> relevanceRole = teamRelevanceRoleService.getRelevanceRole(teamId, id, treeNodeIds);
//        //有权限
//        if (teamRoleDto.size() > 0) {
//            predicate.and(wrap -> {
//                for (int i = 0; i < teamRoleDto.size(); i++) {
//                    if (i == 0){
//                        wrap.eq("id", teamRoleDto.get(i).getTreeNodeId());
//                    }else {
//                        wrap.or().eq("id", teamRoleDto.get(i).getTreeNodeId());
//                    }
//                }
//            });
//
//            //生效日期为空 或 创建人是本人 或 生效日期已经到了
//            predicate.and(wrap -> wrap.isNull("effective_date").or().eq("create_id", id).or().apply("date_format(effective_date, '%Y-%m-%d') <= {0}", DateUtil.getTimeMd()));
//        } else {
//            return null;
//        }
        if (relevanceRole.size() == 0) {
            return teamFilesTreeDto;
        }
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectListTreePage(parentId, null, teamId, relevanceRole, null, null, true, null, null, query.getSort(), null);

        //是否收藏
        SetCollectionDataUtil setCollectionDataUtil = new SetCollectionDataUtil(filesCollectionMapper);
        List<TeamFilesTree> teamFilesTrees2 = setCollectionDataUtil.setCollectionTeamFileData(teamFilesTrees);
        //是否关注
        SetAttentionDataUtil setAttentionDataUtil = new SetAttentionDataUtil(filesAttentionMapper);
        List<TeamFilesTree> teamFilesTrees3 = setAttentionDataUtil.setAttentionTeamData(teamFilesTrees2);

        List<TeamFilesTreeDto> teamFilesTreeDtos = MapstructUtils.convert(teamFilesTrees3, TeamFilesTreeDto.class);
        for (TeamFilesTreeDto filesTreeDto : teamFilesTreeDtos) {
            filesTreeDto.setCreateBy(filesTreeDto.getCreateId());
            filesTreeDto.setUpdateBy(filesTreeDto.getUpdateId());
        }
        teamFilesTreeDto.setChildren(teamFilesTreeDtos);
        return teamFilesTreeDto;
    }


    @Override
    public TeamFilesTree getById(Long id) {
        return teamFilesTreeMapper.selectById(id);
    }

    @Override
    // @Cacheable(key = "'id:' + #p0")
    public TeamFilesTreeDto findById(Long id) {
        return MapstructUtils.convert(getById(id), TeamFilesTreeDto.class);
    }

    @Override
    public List<FilesTree> selectFilesTree(Collection<String> ids) {
        QueryWrapper<TeamFilesTree> predicate = new QueryWrapper<>();
        predicate.in("id", ids)
                .isNull("delete_id")
        ;
        List<TeamFilesTree> list = this.list(predicate);
        return CollectionUtils.isEmpty(list) ? null :
            MapstructUtils.convert(MapstructUtils.convert(list, TeamFilesTreeDto.class), FilesTree.class);
    }

    @Override
    public List<TeamFilesTreeDto> removeNotPermTree(List<TeamFilesTreeDto> teamFilesTreeDtos, Long userId, String roleType) {
        List<TeamFilesTreeDto> newTeamFilesTreeDtos = new ArrayList<>();
        for (TeamFilesTreeDto teamFilesTreeDto : teamFilesTreeDtos) {
            if (teamRelevanceRoleService.checkPermission(String.valueOf(teamFilesTreeDto.getId()), teamFilesTreeDto.getTeamId(), remoteUserService.getUserInfo(userId), TeamParamEnum.DOWNLOAD.getParam())) {
                newTeamFilesTreeDtos.add(teamFilesTreeDto);
            }
        }
        return newTeamFilesTreeDtos;
    }

    @Override
    public TeamFilesTreeDto selectTeamTree(String id) {
        TeamFilesTree teamFilesTree = getTeamTreeById(id);
        TeamFilesTreeDto dto = MapstructUtils.convert(teamFilesTree, TeamFilesTreeDto.class);
        List<TeamFilesTree> childrenTree = getTeamTreeByParentId(id);
        if (childrenTree.size() > 0) {
            for (TeamFilesTree filesTree : childrenTree) {
                String nodeId = String.valueOf(filesTree.getId());
                if (teamRelevanceRoleService.checkPermission(String.valueOf(id), teamFilesTree.getTeamId(), LoginHelper.getLoginUser(), TeamParamEnum.UPDATE.getParam())) {
                    TeamFilesTreeDto teamFilesTreeDto = selectTeamTree(nodeId);
                    dto.getChildren().add(teamFilesTreeDto);
                }
            }
        }
        return dto;
    }

    @Override
    public List<TeamFilesTree> selectJuniorAll(String id) {
        return teamFilesTreeMapper.selectJuniorAll(id, true);
    }

    @Override
    public List<TeamFilesTree> selectJuniorAll(List<String> ids, String deleteType) {
        return teamFilesTreeMapper.selectJuniorAll02(ids, deleteType);
    }

    @Override
    public boolean selectByNodeIdIsOwn(List<String> nodeId, String teamId, boolean b) {
        Long count = this.lambdaQuery()
                .eq(TeamFilesTree::getTeamId, teamId)
                .and(true, e -> {
                    e.eq(TeamFilesTree::getType, TreeTypeEnum.FOLDER.getType())
                            .or()
                            .eq(TeamFilesTree::getType, TreeTypeEnum.HEAD.getType());
                })
                .in(TeamFilesTree::getId, nodeId)
                .isNull(TeamFilesTree::getDeleteId)
                .count();
        if (count < nodeId.size()) {
            if (b) {
                return true;
            }
            throw new RuntimeException("注意：您当前尝试访问的文件夹不属于当前团队。请确认您正在查找的文件夹路径或联系管理员获取更多帮助。");
        }
        return true;
    }

    @Override
    public List<TeamFilesTree> selectSuperiorAll(String id) {
        return teamFilesTreeMapper.selectSuperiorAll(id);
    }


    @Override
    public List<RemoteFilesDownload> folderSonFiles(List<String> ids, Boolean b, String userId) {
        if (CollectionUtils.isEmpty(ids) || ids.size() <= 0) {
            return new ArrayList<>();
        }
        List<FilesTree> trees1 = selectFilesTree(ids);
        List<TreeDownloadFiles> filesList = MapstructUtils.convert(trees1, TreeDownloadFiles.class);


        String join = Joiner.on(",").join(ids);
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectAllSubordinate(join, trees1.get(0).getCreateId(), b);

        List<TeamFilesTreeDto> treeDtos = removeNotPermTree(MapstructUtils.convert(teamFilesTrees, TeamFilesTreeDto.class), Long.valueOf(userId), "3");

        //构建成树结构
        List<RemoteFilesDownload> filesTrees = MapstructUtils.convert(treeDtos, RemoteFilesDownload.class);
//        boolean addAll = filesTrees.addAll(filesList);

//        //处理数据权限
//        List<TreeDownloadFiles> treeList = TreeDownloadFiles.listToTerr(filesTrees, ids, "team");

        return filesTrees;
    }

    public TeamFilesTree getTeamTreeById(String id) {
        QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                .eq("id", id).isNull("delete_id")
                .orderByDesc("create_time")
//                .orderBy(true,true,"type")
                ;
        return this.getOne(queryWrapper);
    }

    public List<TeamFilesTree> getTeamTreeByParentId(String parentId) {
        QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                .eq("parent_id", parentId).isNull("delete_id")
                .orderByDesc("create_time")
//                .orderBy(true,true,"type")
                ;
        return this.list(queryWrapper);
    }

    @Override
    public boolean rename(TeamFilesTreeDto teamFilesTreeDto) {
        TeamFilesTree teamFilesTree = new TeamFilesTree();
        teamFilesTree.setId(teamFilesTreeDto.getId());
        TeamFilesTree byId = getById(teamFilesTree.getId());

        if (nameRechecking(teamFilesTreeDto.getRealName(), byId.getParentId(), byId.getSuffix()) != null) {
            return false;
        }
        //修改自身路径
        teamFilesTree.setRealName(teamFilesTreeDto.getRealName());
        if (byId.getSuperiorsPath() != null) {
            teamFilesTree.setPath(byId.getSuperiorsPath() + "/" + teamFilesTree.getRealName());
        } else {
            teamFilesTree.setPath("/" + teamFilesTree.getRealName());
        }
        teamFilesTree.setUpdateId(String.valueOf(LoginHelper.getUserId()));
        teamFilesTree.setUpdateBy(LoginHelper.getLoginUser().getNickname());
        teamFilesTreeMapper.updateById(teamFilesTree);

        //修改它的所有子文件的路径
        renameChild(teamFilesTree);
        return true;
    }

    public void renameChild(TeamFilesTree teamFilesTree) {
        TeamFilesTreeQueryParam teamFilesTreeQueryParam = new TeamFilesTreeQueryParam();
        QueryWrapper<TeamFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(teamFilesTreeQueryParam);
        predicate.eq("parent_id", teamFilesTree.getId());
        predicate.isNull("delete_id");
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectList(predicate);
        if (teamFilesTrees.size() > 0) {
            for (TeamFilesTree child : teamFilesTrees) {
                child.setSuperiorsPath(teamFilesTree.getPath());
                child.setPath(teamFilesTree.getPath() + "/" + child.getRealName());
                teamFilesTreeMapper.updateById(child);
                renameChild(child);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public TeamFilesTreeDto insert(String parentId, String realName, String teamId, String type) {
        return insert(parentId, realName, teamId, type, null);
    }

    @Transactional(rollbackFor = Exception.class)
    public TeamFilesTreeDto insert(String parentId, String realName, String teamId, String type, String userId) {
        if (userId == null) {
            userId = String.valueOf(LoginHelper.getUserId());
        }
        TeamFilesTreeDto resources = new TeamFilesTreeDto();
        resources.setParentId(parentId);
        resources.setRealName(realName);
        resources.setTeamId(teamId);
        resources.setType(type);
        if (TreeTypeEnum.RICHTEXT.getType().equals(type)) {
            resources.setSuffix(type);
        }
        TeamFilesTree byId = getById(resources.getParentId());
        resources.setSuperiorsPath(byId.getPath());
        resources.setPath(byId.getPath() + "/" + resources.getRealName());
        TeamFilesTree teamFilesTree = nameRechecking(resources.getRealName(), resources.getParentId(), resources.getSuffix());
        TeamFilesTreeDto teamFilesTreeDto = MapstructUtils.convert(teamFilesTree, TeamFilesTreeDto.class);
        if (teamFilesTree == null) {
            TeamFilesTree convert = MapstructUtils.convert(resources, TeamFilesTree.class);
            convert.setCreateId(userId);
            teamFilesTreeMapper.insert(convert);
            return MapstructUtils.convert(convert, TeamFilesTreeDto.class);
        } else {
            teamFilesTreeDto.setDuplicate(true);
            return teamFilesTreeDto;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public TeamFilesTree insert(TeamFilesTreeDto teamFilesTreeDto) {
        TeamFilesTree convert = MapstructUtils.convert(teamFilesTreeDto, TeamFilesTree.class);
        teamFilesTreeMapper.insert(convert);
        return convert;
    }

    @Override
    public TeamFilesTree personalCommit(PersonalFilesTreeVo personalFilesTreeVo, Team team) {
        TeamFilesTree teamFilesTree = MapstructUtils.convert(personalFilesTreeVo, TeamFilesTree.class);
        teamFilesTree.setId(null);
        LoginUser user = LoginHelper.getLoginUser();
        teamFilesTree.setTeamId(String.valueOf(team.getId()));
        //拷贝文件
        if (teamFilesTree.getType().equals(TreeTypeEnum.FILE.getType())) {
            RemoteFile remoteFile = new RemoteFile();
            remoteFile.setOssId(Long.valueOf(teamFilesTree.getStorageId()));
            remoteFile = remoteFileService.copyFile(remoteFile, team.getMinioBucket(), OssModuleType.Team);

//            Storage copy = remoteFileService.copyFile(String.valueOf(user.getUserId()), user.getUsername(), FileEnums.TEAM_FILE, team.getMinioBucket(), teamFilesTree.getStorageId(), null, null);
            teamFilesTree.setStorageId(String.valueOf(remoteFile.getOssId()));
        }
        //添加对象
        teamFilesTreeMapper.insert(teamFilesTree);

        String treeId = String.valueOf(teamFilesTree.getId());
        //继承上级权限
        List<TeamRelevanceRoleDto> list = teamRelevanceRoleService.extendParentPerm(teamFilesTree.getParentId(), treeId);
        //创建日志
        for (TeamRelevanceRoleDto relevanceRoleDto : list) {
            relevanceRoleDto.setPermJson(teamRoleService.getById(relevanceRoleDto.getRoleId()).getParams());
        }
        List<SysLogPerm> collect = list.stream().map(res -> new SysLogPerm(res.getObjectId(), res.getObjectType(), res.getPermJson(), res.getRoleId())).collect(Collectors.toList());
        sysDocLogService.createPermLog(treeId, null, TreeEnum.TEAM, OperationEnum.INSERT.getOperation(OperationEnum.OperationTypeEnum.FOLDER), teamFilesTree.getRealName(), teamFilesTree.getPath(), null, collect);

        for (PersonalFilesTreeVo child : personalFilesTreeVo.getChildren()) {
            child.setParentId(String.valueOf(teamFilesTree.getId()));
            personalCommit(child, team);
        }
        return teamFilesTree;
    }

    @Override
    public TeamFilesTree nameRechecking(String realName, String parentId, String suffix) {
        TeamFilesTreeQueryParam query = new TeamFilesTreeQueryParam();
        QueryWrapper<TeamFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);
        predicate.eq("real_name", realName);
        predicate.eq("parent_id", parentId);
        if (suffix == null) {
            predicate.isNull("suffix");
        } else {
            predicate.eq("suffix", suffix);
        }
        predicate.isNull("delete_id");
        List<TeamFilesTree> teamFilesTrees = teamFilesTreeMapper.selectList(predicate);
        if (teamFilesTrees.size() > 0){
            return teamFilesTrees.get(0);
        }else {
            return null;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateById(TeamFilesTreeDto resources) {
        TeamFilesTree entity = MapstructUtils.convert(resources, TeamFilesTree.class);
        entity.setUpdateId(String.valueOf(LoginHelper.getUserId()));
        entity.setUpdateBy(LoginHelper.getLoginUser().getNickname());
        int ret = teamFilesTreeMapper.updateById(entity);
        // delCaches(resources.id);
        return ret;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeByIds(Set<Long> ids) {
        // delCaches(ids);
        return teamFilesTreeMapper.deleteBatchIds(ids);
    }

    @Override
    public void downloadFile(String id, String fileName, HttpServletResponse response) {
//        fileStorageUtils.downloadFile(id,fileName,response);
    }

    TeamFilesTree getTeamFilesTree(String id) {
        TeamFilesTree parentTree = null;
        if (!StringUtils.isEmpty(id)) {
            parentTree = this.getById(id);
            if (parentTree == null) {
                throw new RuntimeException("非法的父类编号");
            }
        }
        return parentTree;
    }

    public Boolean judgeIsEmpty(String userId, String nickName, String folderName, String parentId, String type,
                                String suffix) {
        QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                .eq("create_id", userId).eq("create_by", nickName)
                .eq("parent_id", parentId).eq("real_name", folderName)
                .isNull("delete_id");
        queryWrapper.eq("type", TreeTypeEnum.find(type).getType());
        if (StringUtils.isNotEmpty(suffix)) {
            queryWrapper.eq("suffix", suffix);
        }
        List<TeamFilesTree> list = this.list(queryWrapper);
        return CollectionUtils.isEmpty(list);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeById(Long id) {
        Set<Long> set = new HashSet<>(1);
        set.add(id);
        return this.removeByIds(set);
    }

    public R fileTreeCopy(RecoverFileChooseAPath chooseAPath) {
        LoginUser user = LoginHelper.getLoginUser(); //用户信息
        String nickName = user.getNickname();
        String minioBucket = user.getMinioBucket();
        String userId = Long.toString(user.getUserId());
        List<String> ids = chooseAPath.getIds();
        String parentId = chooseAPath.getParentId();

        QueryWrapper<TeamFilesTree> wrapper = new QueryWrapper<TeamFilesTree>()
                .eq("id", chooseAPath.getParentId()).isNull("delete_id");
        ;
        TeamFilesTree parentTree = getOne(wrapper);

        if (ObjectUtils.isEmpty(parentTree)) {
            throw new RuntimeException("错误的文件复制");
        }

        if (StringUtils.equalsIgnoreCase(parentTree.getType(), TreeTypeEnum.FILE.getType())) {
            throw new RuntimeException("错误文件复制位置");
        }

        if (JudgmentEmpty(ids, parentId)) {
            throw new RuntimeException("目标目录是源文件的子目录");
        }


        ids.forEach(id -> {
            QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                    .eq("id", id).isNull("delete_id");
            TeamFilesTree filesTree = getOne(queryWrapper);
            QueryWrapper<Team> teamQueryWrapper = new QueryWrapper<Team>().eq("id", filesTree.getTeamId());
            Team team = teamMapper.selectOne(teamQueryWrapper);
            fileTreeCopy(filesTree, parentTree, userId, nickName, team.getMinioBucket(), true);

        });

        return R.ok();
    }

    private void fileTreeCopy(TeamFilesTree filesTree, TeamFilesTree parentTree, String userId, String nickName, String minioBucket, boolean b) {
        String parentPath = parentTree.getPath();
        TeamFilesTree newTree = filesTree.filesCopy(userId, nickName);
        newTree.setSuperiorsPath(parentPath);
        newTree.setPath(parentPath + "/");
        newTree.setParentId(Long.toString(parentTree.getId()));
        newTree.setType(filesTree.getType());
        newTree.setTeamId(filesTree.getTeamId());
        newTree.setUpdateId(userId);
        newTree.setUpdateBy(nickName);

        setParentNodeSize(String.valueOf(parentTree.getId()), filesTree.getSize(), 0);
        if (b) {
            String realName = newTree.getRealName();
            TeamFilesTree teamFilesTree = nameRechecking(realName, String.valueOf(parentTree.getId()), newTree.getSuffix());
            if (teamFilesTree != null) {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                realName += "_" + df.format(new Date());
            }
            newTree.setRealName(realName);
        }
        save(newTree);

        List<TeamRelevanceRoleDto> list = teamRelevanceRoleService.extendParentPerm(newTree.getParentId(), String.valueOf(newTree.getId()));
        //创建日志
        for (TeamRelevanceRoleDto relevanceRoleDto : list) {
            relevanceRoleDto.setPermJson(teamRoleService.getById(relevanceRoleDto.getRoleId()).getParams());
        }
        List<SysLogPerm> collect = list.stream().map(res -> new SysLogPerm(res.getObjectId(), res.getObjectType(), res.getPermJson(), res.getRoleId())).collect(Collectors.toList());
        sysDocLogService.createPermLog(String.valueOf(newTree.getId()), null, TreeEnum.TEAM, OperationEnum.COPY.judgmentType(newTree.getType()), newTree.getRealName(), newTree.getPath(), null, collect);

        //修改团队使用文件大小
        Team team = teamMapper.selectById(filesTree.getTeamId());
        team.setUsedSpace(team.getUsedSpace() + newTree.getSize());
        teamMapper.updateById(team);

        if (StringUtils.equalsIgnoreCase(newTree.getType(), TreeTypeEnum.FILE.getType())) {
            fileCopy(newTree, minioBucket);
        } else {
            folderCopy(String.valueOf(filesTree.getId()), newTree, minioBucket);
        }
    }

    private void fileCopy(TeamFilesTree filesTree, String minioBucket) {
        RemoteFile remoteFile = remoteFileService.selectById(filesTree.getStorageId());
        Team team = teamMapper.selectById(filesTree.getTeamId());
//       数据  是否为空
        if (ObjectUtils.isNotEmpty(remoteFile)) {
            try {
//                Storage copy = fileStorageUtils.copy(filesTree.getCreateId(), filesTree.getCreateBy(), service.getBucketName(), minioBucket, filesTree.getStorageId(),null,null);
                remoteFile = remoteFileService.copyFile(remoteFile,team.getMinioBucket(), OssModuleType.Enterprise);
                    filesTree.setEditionName(remoteFile.getVersionName()); //
                filesTree.setEdition(remoteFile.getVersionId()); //
                filesTree.setStorageId(Long.toString(remoteFile.getOssId()));
//                filesTree.setStorageType();
            } catch (Exception e) {
                e.printStackTrace();
                filesTree.setLinkingState("1");
            }
        }

        updateById(filesTree);
    }

    private void folderCopy(String filesTreeId, TeamFilesTree newTree, String minioBucket) {
//        filesTreeId
        QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                .eq("parent_id", filesTreeId).isNull("delete_id");
        List<TeamFilesTree> filesTrees = list(queryWrapper);
        if (CollectionUtils.isNotEmpty(filesTrees)) {
            filesTrees.forEach(tree -> {
                QueryWrapper<Team> teamQueryWrapper = new QueryWrapper<Team>().eq("id", tree.getTeamId());
                Team team = teamMapper.selectOne(teamQueryWrapper);
                fileTreeCopy(tree, newTree, newTree.getCreateId(), newTree.getCreateBy(), team.getMinioBucket(), false);
            });
        }
    }


    @Override
    public R fileTreeMove(RecoverFileChooseAPath chooseAPath) {
        LoginUser user = LoginHelper.getLoginUser(); //用户信息
        String username = user.getUsername();
        String userId = Long.toString(user.getUserId());
        String parentId = chooseAPath.getParentId();
        List<String> ids = chooseAPath.getIds();

        QueryWrapper<TeamFilesTree> query = new QueryWrapper<TeamFilesTree>()
                .eq("id", chooseAPath.getParentId())
                .isNull("delete_id");
        TeamFilesTree parentTree = getOne(query);

//        ObjectUtils.isEmpty(filesTree)

        if (ObjectUtils.isEmpty(parentTree)) {
            throw new RuntimeException("文件错误的移动");
        }

        if (StringUtils.equalsIgnoreCase(parentTree.getType(), TreeTypeEnum.FILE.getType())) {
            throw new RuntimeException("错误文件文件移动位置");
        }

        if (JudgmentEmpty(ids, parentId)) {
            throw new RuntimeException("目标目录是源文件的子目录");
        }

//        int
        List<TeamFilesTree> success = new ArrayList<>();
        List<TeamFilesTree> exception = new ArrayList<>();
        ids.forEach(id -> {
            QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>()
                    .eq("id", id)
                    .isNull("delete_id");
            //获取要移动的文件
            TeamFilesTree filesTree = getOne(queryWrapper);
            setParentNodeSize(filesTree.getParentId(), filesTree.getSize(), 1);
            setParentNodeSize(parentId, filesTree.getSize(), 0);

            //删除原有权限
//            teamRelevanceRoleService.removeByTreeNodeId(id);
//            //继承新位置的权限
//            List<TeamRelevanceRoleDto> list = teamRelevanceRoleService.extendParentPerm(String.valueOf(parentTree.getId()), id);
            //创建日志
//            for (TeamRelevanceRoleDto relevanceRoleDto : list) {
//                relevanceRoleDto.setPermJson(teamRoleService.getById(relevanceRoleDto.getRoleId()).getParams());
//            }
//            List<SysLogPerm> collect = list.stream().map(res -> new SysLogPerm(res.getUserId(), res.getPermJson(), res.getRoleId())).collect(Collectors.toList());
            sysDocLogService.createLog(id, null, TreeEnum.TEAM, OperationEnum.MOVE.judgmentType(filesTree.getType()), filesTree.getRealName(), filesTree.getPath(), null);

            boolean b = false;
            if (ObjectUtils.isNotEmpty(filesTree)) {
                b = fileTreeMove(parentTree, filesTree, userId, username);
            }
            if (b) {
                success.add(filesTree);
            } else {
                exception.add(filesTree);
            }
        });
        if (CollectionUtils.isNotEmpty(exception) && exception.size() > 0) {
            StringBuilder message = new StringBuilder(success.size() + "个对象移动成功,");
            StringJoiner joiner = new StringJoiner(",");
            exception.forEach(tree -> {
                joiner.add(tree.getRealName());
            });
            message.append(joiner);
            message.append("等");
            message.append(exception.size());
            message.append("对象移动失败");
            return R.ok(message.toString());
        } else {
            return R.ok("移动成功");
        }
    }


    private boolean fileTreeMove(TeamFilesTree parentTree, TeamFilesTree filesTree, String userId, String username) {
        String realName = filesTree.getRealName();
        String parentId = Long.toString(parentTree.getId());
        if (nameRechecking(realName, parentId, filesTree.getSuffix()) != null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            realName += "_" + df.format(new Date());
        }


        String treePath = filesTree.getPath();
        String parentTreePath = parentTree.getPath();
        String newPath = parentTreePath + "/" + realName;

//        filesTree.setParentId(parentId);//设置父编号

//        filesTree.setSuperiorsPath(parentTreePath);//设置父路径
        UpdateWrapper<TeamFilesTree> updateWrapper = new UpdateWrapper<TeamFilesTree>()
                .set("real_name", realName)//设置名字
                .set("path", newPath)//设置路径
                .set("superiors_path", parentTreePath)//设置父路径
                .set("parent_id", parentId)//设置父编号
                .set("update_id", userId).set("update_by", username).set("update_time", new Date())
                .eq("id", filesTree.getId());
        update(updateWrapper);

        //修改儿子路径
        UpdateWrapper<TeamFilesTree> update = new UpdateWrapper<>();
        int length = treePath.length();
        update.setSql("path=INSERT(path,1," + length + ",'" + newPath + "')")
                .setSql("superiors_path=INSERT(superiors_path,1," + length + ",'" + newPath + "')")
                .likeRight("path", treePath).ne("id", filesTree.getId());
        update(update);

        return true;
    }

    public Boolean JudgmentEmpty(List<String> ids, String parentId) {
        if (ids.contains(parentId)) {
            return true;
        }
        HashSet<String> setId = new HashSet<>();
        folderCheck(ids, setId, true);
        if (setId.contains(parentId)) {
            return true;
        }
        return false;
    }

    public void folderCheck(List<String> ids, Set<String> setId, boolean b) {
        if (CollectionUtils.isEmpty(ids) || ids.size() <= 0) {
            return;
        }

        QueryWrapper<TeamFilesTree> queryWrapper = new QueryWrapper<TeamFilesTree>().in("parent_id", ids);
        if (b) {
            queryWrapper.isNull("delete_id");
        } else {
            queryWrapper.isNotNull("delete_id").eq("delete_type", DeleteTypeEnums.NO_DISPLAY.getType());
        }
        List<TeamFilesTree> list = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            List<String> list1 = new ArrayList<>();
            list.forEach(tree -> {
                if (StringUtils.equalsIgnoreCase(TreeTypeEnum.FOLDER.getType(), tree.getType())) {
                    list1.add(String.valueOf(tree.getId()));
                }
                setId.add(String.valueOf(tree.getId()));
            });
            folderCheck(list1, setId, b);
//            throw new BadRequestException("选中的文件夹中有子级，无法删除");
        }
    }

    @Override
    public String createTemplate(Long templateId, Long parentFolderId, String folderName, LoginUser user) {
        EnterpriseFolderTree folderTree = enterpriseFolderTreeService.getById(templateId);
        if (ObjectUtil.isNull(folderTree)) throw new RuntimeException("不存在此模板");
        EnterpriseFilesTree filesTree = enterpriseFilesTreeService.getById(folderTree.getParentId());
        if (ObjectUtil.isNull(filesTree)) throw new RuntimeException("此模板文件夹已不存在，请在企业文档库重新创建");
        TeamFilesTree teamTreeById = getTeamTreeById(parentFolderId.toString());
        if (StringUtils.isEmpty(folderName) || StringUtils.isBlank(folderName))
            throw new RuntimeException("文件夹名为空");
        //检测第一层文件夹名是否冲突
        //检测头文件名是否冲突
        TeamFilesTree nameRechecking = nameRechecking(folderName, parentFolderId.toString(), filesTree.getSuffix());
        if (!ObjectUtil.isNull(nameRechecking)) throw new RuntimeException("文件夹名存在冲突");
        //将头文件夹存入
        filesTree.setSuperiorsPath(teamTreeById.getSuperiorsPath());
        filesTree.setPath(teamTreeById.getPath());
        Team byId = teamMapper.selectById(teamTreeById.getTeamId());
        TeamFilesTree teamFilesTree = new TeamFilesTree();
        teamFilesTree.setParentId(parentFolderId.toString())
                .setSize(filesTree.getSize())
                .setTeamId(teamTreeById.getTeamId())
                .setRealName(folderName)
                .setType(filesTree.getType())
                .setSuperiorsPath(teamTreeById.getPath())
                .setPath(teamTreeById.getPath() + "/" + folderName)
                .setCreateId(user.getUserId().toString())
                .setCreateBy(user.getUsername())
                .setUpdateId(user.getUserId().toString())
                .setUpdateBy(user.getUsername())
                .setTemplateName(folderTree.getRealName())
                .setCreateTime(new Date()).setUpdateTime(new Date()).setUpdateId(user.getUserId().toString()).setUpdateBy(user.getUsername());
        teamFilesTreeMapper.insert(teamFilesTree);
        //继承上级权限
        teamRelevanceRoleService.extendParentPerm(parentFolderId.toString(), String.valueOf(teamFilesTree.getId()));
        createAllChildrenFolder(filesTree, teamFilesTree.getId(), teamFilesTree.getTeamId(), byId.getMinioBucket(), user);

        //修改空间大小
        setParentNodeSize(parentFolderId.toString(), filesTree.getSize(), 0);

        return String.valueOf(teamFilesTree.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    public void createAllChildrenFolder(EnterpriseFilesTree enterpriseFilesTree, Long parentId, String teamId, String srcBucketName, LoginUser user) {
        //优化过后
        List<EnterpriseFilesTree> list = enterpriseFilesTreeService.lambdaQuery()
                .eq(EnterpriseFilesTree::getParentId, enterpriseFilesTree.getId())
                .isNull(EnterpriseFilesTree::getDeleteType)
                .list();
        ArrayList<TeamFilesTree> teamFilesTrees = new ArrayList<>();
        //复制企业文件夹到团队
        for (EnterpriseFilesTree filesTree : list) {
            TeamFilesTree teamFilesTree = new TeamFilesTree();
            if (filesTree.getType().equals(TreeTypeEnum.FILE.getType())) {
                RemoteFile remoteFile = new RemoteFile();
                remoteFile.setOssId(Long.valueOf(filesTree.getStorageId()));
//                Storage copy = fileStorageUtils.copy(user.getUserId().toString(), user.getUsername(), FileEnums.TEAM_FILE, srcBucketName, filesTree.getStorageId(), null, null);
                remoteFile = remoteFileService.copyFile(remoteFile, srcBucketName, OssModuleType.Team);

                teamFilesTree.setTeamId(teamId).setSuffix(remoteFile.getFileSuffix()).setStorageId(remoteFile.getOssId().toString());
            }
            teamFilesTree.setParentId(parentId.toString())
                    .setSize(enterpriseFilesTree.getSize())
                    .setTeamId(teamId)
                    .setRealName(filesTree.getRealName())
                    .setType(filesTree.getType())
                    .setSuperiorsPath(enterpriseFilesTree.getPath())
                    .setPath(enterpriseFilesTree.getPath() + "/" + filesTree.getRealName())
                    .setCreateId(user.getUserId().toString())
                    .setCreateBy(user.getUsername())
                    .setCreateTime(new Date()).setUpdateTime(new Date()).setUpdateId(user.getUserId().toString()).setUpdateBy(user.getUsername());
            teamFilesTrees.add(teamFilesTree);

            //更新目录
            filesTree.setSuperiorsPath(enterpriseFilesTree.getPath());
            filesTree.setPath(enterpriseFilesTree.getPath() + "/" + filesTree.getRealName());
        }
        //插入子文件夹
        saveBatch(teamFilesTrees);
        for (int i = 0; i < list.size(); i++) {
            //继承上级权限
            teamRelevanceRoleService.extendParentPerm(parentId.toString(), String.valueOf(teamFilesTrees.get(i).getId()));
            createAllChildrenFolder(list.get(i), teamFilesTrees.get(i).getId(), teamId, srcBucketName, user);
        }
    }

    public void teamToEnt(TeamFilesTree teamFilesTree, Long parentId, TeamToEnterpriseDto teamToEnterpriseDto) {
        //存入数据库的parentId
        //teamFilesTree
        LoginUser user = LoginHelper.getLoginUser();
        //teamFilesTree为父文件夹
        //查子文件夹
        List<TeamFilesTree> list = teamFilesTreeMapper.selectList(new LambdaQueryWrapper<TeamFilesTree>().eq(TeamFilesTree::getParentId, teamFilesTree.getId()).isNull(TeamFilesTree::getDeleteType));

        //临时表
        ArrayList<TeamToEnterprise> teamToEnterprises = new ArrayList<>();
        for (TeamFilesTree filesTree : list) {
            TeamToEnterprise teamToEnterprise = new TeamToEnterprise();
            if (filesTree.getType().equals(FileTypeEnum.FILE.getCode())) {
                //复制文件到临时库
                RemoteFile remoteFile = new RemoteFile();
                remoteFile.setOssId(Long.valueOf(filesTree.getStorageId()));
                RemoteFile copyFile = remoteFileService.copyFile(remoteFile, OssBucketOneEnum.ENTERPRISE_BUCKET.getCode(), OssModuleType.Enterprise);

//                Storage copy = fileStorageUtils.copy(user.getId().toString(), user.getUsername(), FileEnums.TEMPORARY_FILE, StorageFolderTypeEnum.TEMPLATE_BUCKET.getCode(), filesTree.getStorageId(), null, null);
                teamToEnterprise.setSuffix(copyFile.getFileSuffix()).setStorageId(copyFile.getOssId().toString()).setSize(copyFile.getFileSize());
            }
            teamToEnterprise.setParentId(parentId.toString())
                    .setTeamId(teamFilesTree.getTeamId())
                    .setSize(teamFilesTree.getSize())
                    .setLibraryType(FileEnums.TEMPORARY_FILE.getCode())
                    .setRealName(filesTree.getRealName())
                    .setType(filesTree.getType())
                    .setSuperiorsPath(teamFilesTree.getPath())
                    .setPath(teamFilesTree.getPath() + "/" + filesTree.getRealName())
                    .setCreateId(user.getUserId().toString())
                    .setCreateBy(user.getUsername())
                    .setCreateTime(new Date()).setUpdateTime(new Date()).setUpdateId(user.getUserId().toString()).setUpdateBy(user.getUsername());
            teamToEnterprises.add(teamToEnterprise);
            //更新目录
            filesTree.setSuperiorsPath(teamFilesTree.getPath()).setPath(teamFilesTree.getPath() + "/" + filesTree.getRealName());
        }
        //插入子文件夹
        teamToEnterpriseService.saveBatch(teamToEnterprises);
        //流程变量显示
        List<TeamToEnterpriseDto> children = MapstructUtils.convert(teamToEnterprises, TeamToEnterpriseDto.class);
        teamToEnterpriseDto.setChildren(children);
        for (int i = 0; i < list.size(); i++) {
            teamToEnt(list.get(i), teamToEnterprises.get(i).getId(), children.get(i));
        }
    }

    /**
     * 修改所有上级文件夹大小
     *
     * @param parentId
     * @param size
     * @param addAndMinus 0是增加所有上级大小 1是减少所有上级大小
     */
    @Override
    public void setParentNodeSize(String parentId, Long size, int addAndMinus) {
        if (size == null) {
            size = 0L;
        }
        TeamFilesTree parentFile = getById(parentId);
        if (addAndMinus == 0) {
            if (null == parentFile.getSize()) {
                parentFile.setSize(size);
            } else {
                parentFile.setSize(parentFile.getSize() + size);
            }
        } else {
            parentFile.setSize(parentFile.getSize() - size);
        }

        teamFilesTreeMapper.updateById(parentFile);
        if (null != parentFile.getParentId()) {
            setParentNodeSize(parentFile.getParentId(), size, addAndMinus);
        }
    }

    @Override
    public List<TeamToEnterpriseDto> createFolder(String filesId, String parentId) {
        LoginUser user = LoginHelper.getLoginUser();
        String[] split = filesId.split(",");
        List<TeamToEnterpriseDto> list = new ArrayList<>();
        for (String s : split) {
            if (StringUtils.isBlank(s) || StringUtils.isEmpty(s)) continue;
            else {
                TeamFilesTree byId = getById(s);
                if (ObjectUtil.isNull(byId)) throw new RuntimeException("参数类型传输有误");
                if (!TreeTypeEnum.FOLDER.getType().equals(byId.getType()))
                    throw new RuntimeException("团队文件选择类型必须为文件夹");
                //复制团队到临时表
                TeamToEnterpriseDto teamToEnterprise = new TeamToEnterpriseDto();
                teamToEnterprise.setSize(byId.getSize())
                        .setParentId(parentId)
                        .setTeamId(byId.getTeamId())
                        .setRealName(byId.getRealName())
                        .setType(byId.getType())
                        .setSuperiorsPath("/")
                        .setLibraryType(FileEnums.TEMPORARY_FILE.getCode())
                        .setPath("/" + byId.getRealName())
                        .setCreateId(user.getUserId().toString())
                        .setCreateBy(user.getUsername())
                        .setCreateTime(new Date()).setUpdateTime(new Date()).setUpdateId(user.getUserId().toString()).setUpdateBy(user.getUsername());
                byId.setSuperiorsPath("/").setPath("/" + byId.getRealName());
                teamToEnterpriseService.insert(teamToEnterprise);
                TeamToEnterpriseDto convert = MapstructUtils.convert(teamToEnterprise, TeamToEnterpriseDto.class);
                teamToEnt(byId, teamToEnterprise.getId(), convert);
                list.add(convert);
            }
        }
        return list;
    }

    /**
     * 模板库创建文件到团队
     */
    @SneakyThrows
    @Override
    public TeamFilesTreeDto createFileFromTemplate(Long templateId, Long parentFolderId, String fileName, String type, String tempType) {
        if (StringUtils.isEmpty(fileName) || StringUtils.isBlank(fileName))
            throw new RuntimeException("File name cannot be empty");
        LoginUser user = LoginHelper.getLoginUser();
        //父级
        TeamFilesTree parentTree = getById(parentFolderId);
        if (ObjectUtil.isNull(parentTree)) throw new RuntimeException("此文件夹不存在");

        //同级文件夹
        List<TeamFilesTree> list = teamFilesTreeMapper.selectList(new LambdaQueryWrapper<TeamFilesTree>().eq(TeamFilesTree::getParentId, parentFolderId).isNull(TeamFilesTree::getDeleteType));

        /**
         * 判断文件夹是否为可操作文件夹
         */

        //得到桶
        Team team = teamMapper.selectById(parentTree.getTeamId());
        String minioBucket = team.getMinioBucket();
        if (parentFolderId == null) throw new RuntimeException("所选文件夹为null");
        TeamFilesTree teamFilesTree = new TeamFilesTree();
        RemoteFile storage = new RemoteFile();
        String suffix = "";
        //创建空
        if (templateId == null) {
            String name = "";
            if (StringUtils.isEmpty(type)) throw new RuntimeException("File type cannot be empty");
            teamFilesTree.setRealName(fileName);
            //重命名检查
            for (TeamFilesTree action : list) {
                if (action.getType().equals("folder") || action.getType().equals("head")) {
                    if (fileName.equals(action.getRealName())) {
                        teamFilesTree.setRealName(fileName + System.currentTimeMillis());
                        break;
                    }
                } else if (action.getType().equals("file")) {
                    if (name.equals(action.getRealName() + "." + action.getSuffix())) {
                        teamFilesTree.setRealName(fileName + System.currentTimeMillis());
                        break;
                    }
                }
            }
            //复制文件到团队
//            String insertFile = "template";
//            File newFile = null;
//            switch (type) {
//                case "word":
//                    suffix = "docx";
//                    newFile = FileUtil.createDocx(fileProperties.getFilePath().getTmp() + insertFile + "." + suffix);
//                    break;
//                case "excel":
//                    suffix = "xlsx";
//                    newFile = FileUtil.createExcel(fileProperties.getFilePath().getTmp() + insertFile + "." + suffix);
//                    break;
//                case "ppt":
//                    suffix = "pptx";
//                    newFile = FileUtil.createPpt(fileProperties.getFilePath().getTmp() + insertFile + "." + suffix);
//                    break;
//                default:
//                    throw new RuntimeException("Unknown type: " + type);
//            }
//            name = fileName + "." + suffix;
//            MultipartFile multipartFile = FileUtil.fileToMultipartFile(newFile, name);
//            RemoteFileDto remoteFileDto = RemoteFileDto.builder()
//                .originalFilename(multipartFile.getOriginalFilename())
//                .name(fileName)
//                .contentType("file")
//                .bucketName(minioBucket)
//                .moduleType(OssModuleType.TeamTemplate)
//                .file(multipartFile.getBytes())
//                .build();
//            storage = remoteFileService.upload(remoteFileDto);
//            storage = fileStorageUtils.create(user.getUserId().toString(), user.getUsername(), minioBucket, multipartFile, FileEnums.TEAM_FILE, null);


        } else {
            String storageId = null;

//            if (tempType.equals("template")) {
//                EnterpriseTemplateTree templateTree = templateTreeService.getById(templateId);
//                if (!templateTree.getLibraryType().equals("template"))
//                    throw new RuntimeException("不是模板文件请重新选择");
//                //获取模板数据
//                storageId = templateTree.getStorageId();
//                suffix = templateTree.getSuffix();
//                templateTree.setDownload(templateTree.getDownload() + 1);
//                templateTreeService.updateById(templateTree);
//            }else
            if (tempType.equals("team")) {
                TeamTemplateTree templateTree = teamTemplateTreeService.getById(templateId);
                storageId = templateTree.getStorageId();
                suffix = templateTree.getSuffix();
            }

            //复制模板数据到团队
            teamFilesTree.setRealName(fileName);
//            storage = fileStorageUtils.copy(user.getId().toString(), user.getUsername(), FileEnums.TEAM_FILE, minioBucket, storageId, null, teamFilesTree.getRealName());

            RemoteFile remoteFile = new RemoteFile();
            remoteFile.setOssId(Long.valueOf(storageId));
            storage = remoteFileService.copyFile(remoteFile, minioBucket, OssModuleType.Team);
        }
        TeamFilesTree filesTree = nameRechecking(fileName, String.valueOf(parentTree.getId()), suffix);
        if (ObjectUtils.isNotEmpty(filesTree)) {
            storage.setName(filesTree.getRealName() + "_" + System.currentTimeMillis());
        }
        //复制文件到团队
        teamFilesTree.setParentId(String.valueOf(parentTree.getId()))
                .setRealName(fileName)
                .setSize(storage.getFileSize())
                .setTeamId(parentTree.getTeamId())
                .setType(FileTypeEnum.FILE.getCode())
                .setSuperiorsPath(parentTree.getPath())
                .setPath(parentTree.getPath() + "/" + fileName)
                .setCreateId(user.getUserId().toString())
                .setCreateBy(user.getUsername())
//                .setStorageType(storage.getStorageType())
                .setUpdateId(user.getUserId().toString())
                .setUpdateBy(user.getUsername())
                .setCreateTime(new Date()).setUpdateTime(new Date()).setUpdateId(user.getUserId().toString()).setUpdateBy(user.getUsername())
                .setStorageId(storage.getOssId().toString())
                .setSuffix(storage.getFileSuffix());

        teamFilesTreeMapper.insert(teamFilesTree);
        //权限继承

        teamRelevanceRoleService.extendParentPerm(parentTree.getId().toString(), teamFilesTree.getId().toString());

        TeamFilesTreeDto convert = MapstructUtils.convert(teamFilesTree, TeamFilesTreeDto.class);
        return convert;
//        return null;
    }


    //新增置顶
    @Override
    public R topMark(FilesTreeTop top) {
        List<String> ids = top.getIds();
        boolean isTop = top.isTop();
        if (ids == null) throw new RuntimeException("传递参数为空");
        for (String id : ids) {

            if (id == null) throw new RuntimeException("id为空");
            TeamFilesTree teamFilesTree = getById(id);
            if (teamFilesTree == null) throw new RuntimeException("文件不存在");

            //团队角色权限
            if (!teamRelevanceRoleService.checkPermission(teamFilesTree.getParentId(), teamFilesTree.getTeamId(), LoginHelper.getLoginUser(), TeamParamEnum.UPDATE.getParam())) {
                return R.fail(ResultEnum.PERM_ERROR.getNum(), "无修改权限，请联系管理员");
            }
        }
        baseMapper.update(new LambdaUpdateWrapper<TeamFilesTree>()
                .in(TeamFilesTree::getId, top.getIds())
                .set(TeamFilesTree::getSort, isTop ? -1 : 0)
            );
        return R.ok();
    }

    @Override
    public TeamFilesTreeDto selectTree(TeamFilesTreeQueryParam query) {
        LoginUser user = LoginHelper.getLoginUser();
        Long id = user.getUserId();
        String parentId = query.getParentId();
        String teamId = query.getTeamId();
        TeamFilesTree teamFilesTree = teamFilesTreeMapper.selectById(parentId);
        TeamFilesTreeDto convert = MapstructUtils.convert(teamFilesTree, TeamFilesTreeDto.class);

        List<TeamRelevanceRole> relevanceRole = teamRelevanceRoleService.getRelevanceRole(teamId, id, null);

        if (relevanceRole.size() == 0) {
            return convert;
        }
        List<TeamFilesTree> childrenTrees = teamFilesTreeMapper.getFolderByParentId(parentId, teamId, relevanceRole, query.getSort());
        convert.setChildren(MapstructUtils.convert(childrenTrees, TeamFilesTreeDto.class));
        return convert;
    }

    @Override
    public TableDataInfo<TeamFilesTreeDto> selectTreePage(TeamFilesTreeQueryParam query, Pageable pageable) {
        LoginUser user = LoginHelper.getLoginUser();
        Long id = user.getUserId();
        String teamId = query.getTeamId();
        long startTime1 = System.currentTimeMillis();
        List<TeamRelevanceRole> relevanceRole = teamRelevanceRoleService.getRelevanceRole(teamId, id, null);
        long endTime1 = System.currentTimeMillis();
        long executionTime1 = endTime1 - startTime1;
        System.out.println("22222Startup method took: " + (executionTime1/1000) + " 秒");
        IPage<PersonalFilesTree> queryPage = PageUtil.toMybatisPage(pageable);
        IPage<TeamFilesTree> treeIPage = teamFilesTreeMapper.selectTreePage(query, queryPage, relevanceRole);
        List<TeamFilesTree> records = treeIPage.getRecords();
        //添加收藏关注标识
        SetCollectionDataUtil setCollectionDataUtil = new SetCollectionDataUtil(filesCollectionMapper);
        SetAttentionDataUtil setAttentionDataUtil = new SetAttentionDataUtil(filesAttentionMapper);
        treeIPage.setRecords(setAttentionDataUtil.setAttentionTeamData(setCollectionDataUtil.setCollectionTeamFileData(records)));

        return MapstructUtils.convertTableDataInfo(TableDataInfo.build(treeIPage),TeamFilesTreeDto.class);
    }

    /***
     *  得到文件树并且返回数据
     * @param treeNodeIdsList
     * @date 2024/3/4 17:55
     * @description
     */
    @Override
    public List<TeamFilesTreeDto> wFlowCopyTree(List<Long> treeNodeIdsList) {
        LoginUser user = LoginHelper.getLoginUser();
        List<TeamFilesTreeDto> teamFilesTreeDtos = new ArrayList<>();
        //拷贝文件到临时库
        for (Long treeNodeId : treeNodeIdsList) {
            teamFilesTreeDtos.add(wFlowCopyFileTree(treeNodeId, null, user.getUserId().toString(), user.getUsername(), JSONObject.toJSONString(treeNodeIdsList)));
        }
        return teamFilesTreeDtos;
    }

    public TeamFilesTreeDto wFlowCopyFileTree(Long treeNodeId, Long newTreeNodeId, String userId, String userName, String key) {
        TeamFilesTree byId = getById(treeNodeId);
        TeamFilesTreeDto convert = MapstructUtils.convert(byId, TeamFilesTreeDto.class);
        TeamToEnterpriseDto teamToEnterpriseDto = MapstructUtils.convert(convert, TeamToEnterpriseDto.class);
        teamToEnterpriseDto.setParentId(String.valueOf(newTreeNodeId));
        teamToEnterpriseDto.setId(null);
        if (byId != null) {
            //复制文件数据
            if (convert.getType().equals(TreeTypeEnum.FILE.getType())) {
                RemoteFile remoteFile = new RemoteFile();
                remoteFile.setOssId(Long.valueOf(convert.getStorageId()));
                RemoteFile copyFile = remoteFileService.copyFile(remoteFile, OssBucketOneEnum.TEMPLATE_BUCKET.getCode(), OssModuleType.Template);

//                Storage copy = fileStorageUtils.copy(userId, userName, FileEnums.TEMPORARY_FILE, StorageFolderTypeEnum.TEMPORARY_FILES.getCode(), convert.getStorageId(), null, null);
                teamToEnterpriseDto.setStorageId(copyFile.getOssId().toString());
                teamToEnterpriseDto.setEdition(copyFile.getVersionId());
            } else if (convert.getType().equals(TreeTypeEnum.RICHTEXT.getType())) {
//                //复制表单数据
//                SysFormDocQueryParam sysFormDocQueryParam = new SysFormDocQueryParam();
//                sysFormDocQueryParam.setTreeNodeId(treeNodeId.toString());
//                sysFormDocQueryParam.setType(TreeEnum.ENTERPRISE.getNum());
//                SysFormDocDto sysFormDocDto = sysFormDocService.query(sysFormDocQueryParam);
//                teamToEnterpriseDto.setFormDocJson(JSONObject.toJSONString(sysFormDocDto));
//                SysFormDocFileQueryParam sysFormDocFileQueryParam = new SysFormDocFileQueryParam();
//                sysFormDocFileQueryParam.setFormDocId(String.valueOf(sysFormDocDto.getId()));
//                List<SysFormDocFileDto> sysFormDocFileDtos = sysFormDocFileService.queryAll(sysFormDocFileQueryParam);
//                List<Storage> storages = new ArrayList<>();
//                for (SysFormDocFileDto sysFormDocFileDto : sysFormDocFileDtos) {
//                    Storage storage = fileStorageUtils.copy(userId.toString(), userName, FileEnums.TEMPORARY_FILE, StorageFolderTypeEnum.TEMPORARY_FILES.getCode(), sysFormDocFileDto.getStorageId(), null, null);
//                    storages.add(storage);
//                }
//                teamToEnterpriseDto.setStoragesJson(JSONArray.toJSONString(storages));
            }
            teamToEnterpriseDto.setDeleteBy(key);
            teamToEnterpriseService.insert(teamToEnterpriseDto);
            convert.setId(teamToEnterpriseDto.getId());
            convert.setParentId(teamToEnterpriseDto.getParentId());
            convert.setStorageId(teamToEnterpriseDto.getStorageId());
            convert.setEdition(teamToEnterpriseDto.getEdition());
            List<TeamFilesTree> list = baseMapper.selectList(new LambdaQueryWrapper<TeamFilesTree>().eq(TeamFilesTree::getParentId, treeNodeId).isNull(TeamFilesTree::getDeleteId));
            List<TeamFilesTreeDto> teamFilesTreeDtos = MapstructUtils.convert(list, TeamFilesTreeDto.class);
            if (list.size() > 0) {
                for (TeamFilesTreeDto teamFilesTreeDto : teamFilesTreeDtos) {
                    TeamFilesTreeDto children = wFlowCopyFileTree(teamFilesTreeDto.getId(), teamToEnterpriseDto.getId(), userId, userName, key);
                    convert.getChildren().add(children);
                }
            }
            return convert;
        } else {
            return new TeamFilesTreeDto();
        }
    }

    @Override
    public List<DataItem> getAllParentId(String parentId) {
        ArrayList<DataItem> strings = new ArrayList<>();
        getParentId(parentId, strings);
        return strings;
    }

    @Override
    public int selectByIdTreePageInfo(String treeId, String parentId, int size, List<String> sort, List<TeamRelevanceRole> relevanceRole) {
        return teamFilesTreeMapper.selectByIdTreePageInfo(treeId, parentId, size, sort, relevanceRole);
    }

    @Override
    public TableDataInfo<FilesTree> SearchTeamFileTreePage(SearchFilesInfoDto infoDto, List<TeamRelevanceRole> relevanceRole, Pageable pageable) {
        IPage queryPage = PageUtil.toMybatisPage(pageable);
        IPage<FilesTree> treeIPage = null;
        if (infoDto.getLabelTypeIds() == null) {
            treeIPage = teamFilesTreeMapper.SearchTeamFileTreePage(infoDto, queryPage, relevanceRole);
        } else {
            treeIPage = teamFilesTreeMapper.SearchTeamFileTreeByLabelPage(infoDto, queryPage, relevanceRole);
        }

        return TableDataInfo.build(treeIPage);
    }

    @Override
    public List<TeamFilesTree> nameRecheckingVerifyData(String parentId) {
        return teamFilesTreeMapper.nameRecheckingVerifyData(parentId);
    }

    @Override
    public void createFileToEs(Long dataId) {
        TeamFilesTree newFileTree = getById(dataId);

        List<TeamRelevanceRole> users = teamRelevanceRoleService.list(new LambdaQueryWrapper<TeamRelevanceRole>().eq(TeamRelevanceRole::getObjectType,PermTypeEnum.USER.getPermTypeCode()).eq(TeamRelevanceRole::getTreeNodeId,newFileTree.getId()));
        List<String> usersList = new ArrayList<>();
        for (TeamRelevanceRole user : users) {
            Long objectId = user.getObjectId();
            usersList.add(String.valueOf(objectId));
        }

        List<TeamRelevanceRole> depts = teamRelevanceRoleService.list(new LambdaQueryWrapper<TeamRelevanceRole>().eq(TeamRelevanceRole::getObjectType,PermTypeEnum.DEPT.getPermTypeCode()).eq(TeamRelevanceRole::getTreeNodeId,newFileTree.getId()));
        List<String> deptList = new ArrayList<>();
        for (TeamRelevanceRole dept : depts) {
            Long objectId = dept.getObjectId();
            deptList.add(String.valueOf(objectId));
        }

        List<TeamRelevanceRole> jobs = teamRelevanceRoleService.list(new LambdaQueryWrapper<TeamRelevanceRole>().eq(TeamRelevanceRole::getObjectType,PermTypeEnum.JOB.getPermTypeCode()).eq(TeamRelevanceRole::getTreeNodeId,newFileTree.getId()));
        List<String> jobsList = new ArrayList<>();
        for (TeamRelevanceRole job : jobs) {
            Long objectId = job.getObjectId();
            jobsList.add(String.valueOf(objectId));
        }

        List<TeamRelevanceRole> roles = teamRelevanceRoleService.list(new LambdaQueryWrapper<TeamRelevanceRole>().eq(TeamRelevanceRole::getObjectType,PermTypeEnum.ROLE.getPermTypeCode()).eq(TeamRelevanceRole::getTreeNodeId,newFileTree.getId()));
        List<String> rolesList = new ArrayList<>();
        for (TeamRelevanceRole role : roles) {
            Long objectId = role.getObjectId();
            rolesList.add(String.valueOf(objectId));
        }

        RemoteEsFilesTree build = RemoteEsFilesTree.builder().id(newFileTree.getId()).parentId(newFileTree.getParentId())
            .createBy(Long.valueOf(newFileTree.getCreateId()))
            .storageId(newFileTree.getStorageId())
            .versionId(newFileTree.getEdition())
            .versionName(newFileTree.getEditionName())
            .teamId(newFileTree.getTeamId())
            .realName(newFileTree.getRealName())
            .suffix(newFileTree.getSuffix())
            .size(newFileTree.getSize())
            .libraryType(TreeEnum.ENTERPRISE.getType())
            .userIdList(usersList)
            .deptIdList(deptList)
            .postIdList(jobsList)
            .roleIdList(rolesList)
            .type(newFileTree.getType()).build();
        try {
            String uuid = "";
            if (newFileTree.getEsId() == null){
                uuid = remoteOssEsService.insert(build);

            }else {
                build.setEsId(newFileTree.getEsId());
                uuid = remoteOssEsService.update(build);
            }
            newFileTree.setEsId(uuid);
            updateById(newFileTree);
        } catch (Exception e) {
            log.error("同步到es失败", e);
        }
    }

    @Override
    public List<FilesTree> selectTreeByDownloadFile(List<String> idList, Long userId) {
        List<FilesTree> list = new ArrayList<>();
        for (String id : idList) {
            list.add(MapstructUtils.convert(getTeamFilesTree(id),FilesTree.class));
            List<TeamFilesTree> teamFilesTrees = selectJuniorAll(id);
            for (TeamFilesTree teamFilesTree : teamFilesTrees) {
                if (teamRelevanceRoleService.checkPermission(String.valueOf(id), teamFilesTree.getTeamId(), remoteUserService.getUserInfo(userId), TeamParamEnum.DOWNLOAD.getParam())) {
                    list.add(MapstructUtils.convert(teamFilesTree,FilesTree.class));
                }
            }

        }
        return list;
    }

    @Override
    public TeamFilesTree createFile(RemoteFilesUpload remoteFilesUpload, String parentId, String fileName, String remarks, Object o, String string, String username, LoginUser user) {
        TeamFilesTree parentTree = getById(parentId);
        TeamFilesTreeDto teamFilesTreeDto = new TeamFilesTreeDto();
        teamFilesTreeDto.setTeamId(parentTree.getTeamId());
        teamFilesTreeDto.setRealName(remoteFilesUpload.getFileName());
        teamFilesTreeDto.setParentId(parentId);
//        teamFilesTreeDto.setLibraryId(parentTree.getLibraryId());
        teamFilesTreeDto.setSuffix(remoteFilesUpload.getFileSuffix());
        teamFilesTreeDto.setStorageId(remoteFilesUpload.getStorageId().toString());
        teamFilesTreeDto.setCreateId(String.valueOf(user.getUserId()));
        teamFilesTreeDto.setCreateBy(user.getNickname());
//        teamFilesTreeDto.setFileDatasetId(fileDatasetId);
        teamFilesTreeDto.setPath(parentTree.getPath() + "/" + remoteFilesUpload.getFileName());
        teamFilesTreeDto.setSuperiorsPath(parentTree.getPath());
        teamFilesTreeDto.setType(FileTypeEnum.FILE.getCode());
//        enterpriseFilesTree.setStorageType(remoteFilesUpload.getStorageType());
        teamFilesTreeDto.setSize(remoteFilesUpload.getFileSize());
        teamFilesTreeDto.setEditionName(remoteFilesUpload.getVersionName());
        teamFilesTreeDto.setEdition(remoteFilesUpload.getVersionId());
//        teamFilesTreeDto.setFileEncode(fileEncode);
        if (!cn.cdeden.common.core.utils.StringUtils.isNullOrBlank(remarks)) teamFilesTreeDto.setRemarks(remarks);
        setParentNodeSize(parentId, remoteFilesUpload.getFileSize(), 0);
        return insert(teamFilesTreeDto);
    }

    @Override
    public List<RemoteFilesDownload> teamDownloadFile(List<String> idList, Long userId) {
        List<FilesTree> filesTrees1 = selectTreeByDownloadFile(idList, userId);
        List<RemoteFilesDownload> treeList = new ArrayList<>();
        filesTrees1.forEach(v -> {
            treeList.add(RemoteFilesDownload.builder()
                .id(v.getId().toString())
                .storageId(v.getStorageId())
                .dateId(v.getId().toString())
                .parentId(idList.contains(v.getId().toString()) ? null : v.getParentId())
                .fileSize(v.getSize())
                .fileName(v.getRealName())
                .fileSuffix(v.getSuffix())
                .isFolder(v.getType().equals("folder"))
                .versionId(v.getEdition())
                .versionName(v.getEditionName())
//                .isFolder(v.getLibraryType().equals("folder"))
                .build());
        });


//        if (CollectionUtils.isNotEmpty(treeList)) {
//            treeList.forEach(tree -> tree.setLibraryType("team")); //设置库的类型
//            List<RemoteFilesDownload> filesTrees = folderSonFiles(idList, true, String.valueOf(userId));
//            if (CollectionUtils.isNotEmpty(filesTrees)) {
//                Stack<RemoteFilesDownload> stack = new Stack<>();
//                for (RemoteFilesDownload filesTree : filesTrees) {
//                    stack.push(filesTree);
//                }
//
//
//                while (!stack.isEmpty()) {
//                    RemoteFilesDownload pop = stack.pop();
//                    treeList.add(pop);
//                    List<RemoteFilesDownload> children = pop.getChildren();
//                    if (children.size() > 0 || children == null) {
//                        for (RemoteFilesDownload child : children) {
//                            stack.push(child);
//                        }
//                    }
//                }
//            }
//        }
        return treeList;
    }

    public void getParentId(String parentId, ArrayList<DataItem> strings) {
        TeamFilesTree one = teamFilesTreeMapper.selectOne(new LambdaQueryWrapper<TeamFilesTree>().eq(TeamFilesTree::getId, parentId));
        strings.add(new DataItem(one.getRealName(),one.getId().toString()));
        if (one.getParentId() == null) return;
        getParentId(one.getParentId(), strings);
    }
}
